<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>v-for</title>
</head>
<!-- v-for根据数据生成列表的结构 -->
<!-- 通常可以和数组等结合使用 -->

<body>
    <div id="eat">
        <input type="button" value="添加元素" @click="add">
        <input type="button" value="删除元素" @click="remove">
        <ul>
            <!-- 这个item是数据值在数组中的是个占位符，还可以和index联用 -->
            <!-- <li v-for="item in arr">
                吃什么{{item}}
            </li> -->
            <li v-for="(item,index) in arr">
                {{index+1}}要吃{{item}}
            </li>
        </ul>
        <h1 v-for="(item,index) in Arrdata" v-bind:title="item.name">
            {{index}} {{item.name}}
        </h1>
    </div>

</body>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script>
    var eat = new Vue({
        el: "#eat",
        data: {
            arr: ["西红柿炒鸡蛋", "蛋炒西红柿"],
            //也可以是一个对象数组
            Arrdata: [{
                name: "佩奇"
            }, {
                name: "乔治"
            }]
        },
        //控制按钮增添数据
        methods: {
            add: function() {
                this.Arrdata.push({
                    name: "花园宝宝"
                })
            },
            remove: function() {
                this.Arrdata.shift()
            }
        }

    })
</script>

</html>
